package com.geoserver.service;

import com.alibaba.fastjson.JSON;
import com.geoserver.dao.SensorDao;
import com.geoserver.entity.Sensor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * FileName: SensorService
 * Create by fengzheng on 2019/4/28 22:37
 * Description: 传感器数据服务
 */

@Service
public class SensorService {

    private SensorDao sensorDao;

    @Autowired
    public SensorService(SensorDao sensorDao) {
        this.sensorDao = sensorDao;
    }

    public String queryData(int sn){
        HashMap<String,Object> hashMap = new HashMap<>();

        try {
            ArrayList<Sensor> sensorArrayList = sensorDao.queryData(sn);

            hashMap.put("status","ok");
            hashMap.put("info",sensorArrayList);

            return JSON.toJSONString(hashMap);
        } catch (Exception e) {
            e.printStackTrace();

            hashMap.put("status","error");
            return JSON.toJSONString(hashMap);
        }
    }
}
